package com.hmj.excel;

import com.alibaba.fastjson.JSONObject;
import com.hmj.excel.biz.ExcelPrase;
import com.hmj.excel.biz.FinanceService;
import com.hmj.excel.frame.ExcelJFrame;
import com.hmj.excel.frame.ExcelWindowAdapter;

import javax.swing.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;



public class Application {
    public static void main(String[] args) throws IOException {
        JFrame jf = new ExcelJFrame();
        jf.addWindowListener(new ExcelWindowAdapter());
        System.out.println("Hello world!");
//        testDiff();
    }

    private void test() throws IOException {
        File test = new File("d:/test.xlsx");
        File test2 = new File("d:/test2.xls");
        if(!test2.exists()){
            test2.createNewFile();
        }
        Map title = new HashMap();
        List<JSONObject> dataList = ExcelPrase.readExcelFile(test, title);
        FinanceService.expressAndTax("B-C-3500",dataList,title);
        OutputStream out = new FileOutputStream(test2);
        ExcelPrase.exportExcelFile(out,dataList,title);
        out.close();
    }

    private static void testDiff() throws IOException {
        File file1 = new File("d:/test.xlsx");
        File file2 = new File("d:/test2.xls");
        File file3 = new File("d:/test4.xlsx");
        if(!file3.exists()){
            file3.createNewFile();
        }

        Map title = new HashMap();
        List<JSONObject> dataList = FinanceService.exportDiffExcel("D", file1, file2, title);
        OutputStream ou = new FileOutputStream(file3);
        ExcelPrase.exportExcelFile(ou,dataList,title);
    }

    private static void testChangeDiff() throws IOException {
        File file1 = new File("d:/test.xlsx");
        File file2 = new File("d:/test2.xls");
        File file3 = new File("d:/test4.xlsx");
        if(!file3.exists()){
            file3.createNewFile();
        }

        Map title = new HashMap();
        List<JSONObject> dataList = FinanceService.exportChangeDataExcel("D","B" ,file1, file2, title);
        OutputStream ou = new FileOutputStream(file3);
        ExcelPrase.exportExcelFile(ou,dataList,title);
    }
}
